Skip to content

Record support by transformation#3758

Draft
wadoon wants to merge 8 commits intomainfrom
weigl/recordbytrans
Draft

Record support by transformation#3758
wadoon wants to merge 8 commits intomainfrom
weigl/recordbytrans

Conversation

@wadoon
Copy link
Copy Markdown
Member

@wadoon wadoon commented Mar 11, 2026

Related Issue

This pull request is part of #3774.

Intended Change

Add a JavaTransformer to handle RecordDeclarations by down-compiling to regular Java classes. The regular pattern looks as:

#modifier record #name(#mod1 #type1 #field1, ...
                       #modN #typeN #fieldN) {
   #bodydeclarations 
}

becomes to:

#modifier #(static when inner-record) final class #name extends java.lang.Record {
   private final #mod1 #type1 #fieldn; 
   ...
   private final #mod1 #typeN #fieldN; 

   public #type1 #name1() { return #name1;} ...
   public #typeN #nameN() { return #nameN;}

   #bodydeclarations 
 
   //# if equals(Object) \not\in #bodydeclaration 
   public final boolean equals(Object o) {
      if(o instanceOf #name n) {
        return java.lang.Objects.equals(#name1, n.#name1) && ... && 
                 java.lang.Objects.equals(#nameN, n.#nameN); 
   }

   //# if hashCode() \not\in #bodydeclaration 
   public final int hashCode() {
      return java.lang.Objects.hash(#name1, ..., #nameN);
   }

   //# if toString() \not\in #bodydeclaration 
   public final String toString() {
      return #name + "["+ 
         ("#name1:" + #name1+",") + ... +
         ("#nameN:" + #nameN+",") + "]";
   }
}

Plan

  • Implement the Java rewriting
  • Contracts?!

Type of pull request

  • New feature (non-breaking change which adds functionality)
  • There are changes to the (Java) code

Ensuring quality

  • I added new test case(s) for new functionality.

@wadoon wadoon changed the base branch from main to weigl/key-javaparser3 March 11, 2026 20:14
@wadoon wadoon mentioned this pull request Mar 17, 2026
24 tasks
@wadoon wadoon force-pushed the weigl/recordbytrans branch from 851457a to bb134dd Compare March 17, 2026 08:48
@wadoon wadoon self-assigned this Mar 17, 2026
@wadoon wadoon added this to the NextMinor milestone Mar 17, 2026
@wadoon wadoon force-pushed the weigl/recordbytrans branch from d7d0301 to 06781a5 Compare March 18, 2026 22:47
@wadoon wadoon force-pushed the weigl/key-javaparser3 branch from ddc8930 to a0ae6e5 Compare March 19, 2026 14:34
Base automatically changed from weigl/key-javaparser3 to main March 28, 2026 21:34
@wadoon wadoon force-pushed the weigl/recordbytrans branch from 2fcc2e6 to 5c6e119 Compare March 28, 2026 23:13
@wadoon wadoon requested a review from unp1 April 1, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant